﻿// <copyright file="PropertyExtensions.cs" company="Auros Ltd.">
//     Copyright (c) Auros Ltd. All rights reserved.
// </copyright>

using System.Linq;
using umbraco.interfaces;
using Umbraco.Core.Models;

namespace Auros.Categorisation
{
    /// <summary>
    /// Class of extension methods for umbraco.interfaces.IProperty.
    /// </summary>
    public static class PropertyExtensions
    {
        /// <summary>
        /// Gets the value of the property as an array of integers.
        /// </summary>
        /// <param name="currentProperty">The current property.</param>
        /// <param name="separator">The character which the value string uses between integers.</param>
        /// <returns>Array of integers.</returns>
        public static int[] GetValueAsIntArray(this IProperty currentProperty, char separator = ',')
        {
            if (!string.IsNullOrEmpty(currentProperty.Value))
                return StringHelpers.StringToIntList(currentProperty.Value, separator).ToArray();

            return new int[0];
        }

        /// <summary>
        /// Gets the value of the property as an array of integers.
        /// </summary>
        /// <param name="currentProperty">The current property.</param>
        /// <param name="separator">The character which the value string uses between integers.</param>
        /// <returns>Array of integers.</returns>
        public static int[] GetValueAsIntArray(this IPublishedContentProperty currentProperty, char separator = ',')
        {
            if (!string.IsNullOrEmpty(currentProperty.Value as string))
                return StringHelpers.StringToIntList(currentProperty.Value as string, separator).ToArray();

            return new int[0];
        }
    }
}